package cn.itcast.controller;

/*import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;*/
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Controller
@RequestMapping(path = "/user")
public class UserController {
    public void TestGit(){
        System.out.println("第一次往主分支提交");
        System.out.println("第二次往dev分支提交");
        System.out.println("在远程更新devA分支内容2");
    }

    public void TestGit2(){
        System.out.println("第一次提交本地分支gaoqi");
        System.out.println("第二次提交主分支");
        System.out.println("第二次提交本地分支gaoqi");
    }
    @RequestMapping(path = "/fileupload1")
    public String fileupload1(HttpServletRequest request, MultipartFile upload) throws IOException {
        System.out.println("springmvc文件上传...");
        //上传的位置
        String path=request.getSession().getServletContext().getRealPath("/uploads/");
        //判断该路径是否存在,没有就创建一个
        File file=new File(path);
        if(!file.exists()){
            file.mkdirs();
        }
        //获取上传文件的名称
        String filename=upload.getOriginalFilename();
        //把文件的名称设置唯一值，uuid
        String uuid= UUID.randomUUID().toString().replace("-","");
        filename=uuid+"_"+filename;
        //完成文件的上传
        upload.transferTo(new File(path,filename));
        return "success";
    }

  /*  @RequestMapping(path = "/fileupload2")
    public String fileupload2(MultipartFile upload) throws IOException {
        System.out.println("springmvc跨服务器文件上传...");
       //定义上传文件服务器的路径
        String path="http://localhost:9090/mvc_fileuploads_war_exploded/uploads/";
        //获取上传文件的名称
        String filename=upload.getOriginalFilename();
        //把文件的名称设置唯一值，uuid
        String uuid= UUID.randomUUID().toString().replace("-","");
        filename=uuid+"_"+filename;
        //创建客户端对象
        Client client = Client.create();
        //和图片服务器进行连接
        WebResource resource = client.resource(path + filename);
        //上传文件
        resource.put(upload.getBytes());
        return "success";
    }*/
    @RequestMapping(path = "/test")
    public String test(){
        System.out.println("测试环境搭建");
        return "success";
    }
}
